package resoft.jeasyform.event;

import resoft.jeasyform.components.Window;
import resoft.jeasyform.components.Component;

/**
 * <p>min length</p>
 * User: albert
 * Date: Aug 28, 2007
 * Time: 2:25:09 AM
 */
public class MinLengthEventHandler implements EventHandler{
    public MinLengthEventHandler(int minLength) {
        if(minLength>0) {
            this.minLength = minLength;
        }
    }
    public boolean execute(Window window, Component source, int eventType) {
        String value = window.getValue(source.getName());
        if(value!=null && value.length()<minLength) {
            String msg = window.getProperty("MinLengthMessage");
            if(!msg.equals("")) {
                window.setMessage(msg);
            }
            return false;
        } else {
            return true;
        }
    }
    private int minLength = 0;
}
